﻿using UnityEngine;
using System.Collections;

namespace play{
	public class BaseFail : MonoBehaviour {

		// Use this for initialization
		void Start () {
		
		}
		
		// Update is called once per frame
		void Update () {
		
		}

		void OnTriggerEnter2D(Collider2D c) {
print ("base bomb, game over");
			// gameover 页面
			if(Network.peerType == NetworkPeerType.Disconnected){
			GameObject.FindGameObjectWithTag("MainCamera").transform.GetComponent<Main>().gameoverAfterSec(2);
			}
		}

		void OnNetworkInstantiate(NetworkMessageInfo info){
			if(networkView.isMine){
print("add base into array");
			gameObject.GetComponent<BaseFail>().enabled = false;
			Config.bases.Add(gameObject);
			networkView.RPC("sentRef",RPCMode.All,gameObject.networkView.viewID);  
			}
		}




 [RPC]
		public void sentRef(NetworkViewID id){
			GameObject enemyBase = NetworkView.Find(id).gameObject;
			if(!enemyBase.networkView.isMine){
				Config.bases.Add(enemyBase);
			}

		}

	}
}